import axios from 'axios'

async function addSchool(schoolInfo) {
    const resp = await axios.post('/api/admin/addSchool', schoolInfo, {
        params: {
            adminWeID: localStorage.getItem('adminWeID')
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}

async function addEnterprise(enterpriseInfo) {
    const resp = await axios.post('/api/admin/addEnterprise', enterpriseInfo, {
        params: {
            adminWeID: localStorage.getItem('adminWeID')
        }
    })
        .catch((e) => {
            window.$message.error(e.response.data.message)
        })
    return resp.data
}

async function getSchools(keyword) {
    const resp = await axios.get('/api/admin/displaySchool', {
        params: {
            keyword: keyword
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

async function getEnterprises(keyword) {
    const resp = await axios.get('/api/admin/displayEnterprise', {
        params: {
            keyword: keyword
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

async function deleteEnterprise(enterpriseWeID) {
    const resp = await axios.delete('/api/admin/deleteEnterprise', {
        params: {
            WeID: enterpriseWeID
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

async function recognizeSchool(schoolWeID) {
    const resp = await axios.post('api/admin/recognizeSchool', null, {
        params: {
            schoolWeID: schoolWeID
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

async function deRecognizeSchool(schoolWeID) {
    const resp = await axios.post('api/admin/deRecognizeSchool', null, {
        params: {
            schoolWeID: schoolWeID
        }
    }).catch((e) => {
        window.$message.error(e.response.data.message)
    })
    return resp.data
}

export default {
    addSchool, addEnterprise, getSchools, getEnterprises, recognizeSchool, deRecognizeSchool, deleteEnterprise
}